home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / raytrace / rayslide / rayslide.lha / ray-slides / ray / hf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-14  |  1.6 KB  |  81 lines

  1. /* hf.c -- Convert GNUplot data to Heightfield format
  2.  
  3.     Program by:  Mark Maimone   31-May-92   CMU Computer Science
  4.  
  5. HISTORY
  6.     13-Sep-92  Mark Maimone (mwm)  Removed site-specfic code.  It still
  7.         only works on 50x50 data though...
  8.  
  9.     31-May-92  Mark Maimone (mwm)  Created.
  10. */
  11.  
  12. #include <stdio.h>
  13.  
  14. int show_help = 0;
  15.  
  16. /* INCLUDE PARSE STATE VARIABLES HERE */
  17.  
  18. char *this_program;
  19.  
  20. main (argc, argv)
  21. int argc;
  22. char **argv;
  23. {
  24.     this_program = argv[0] ? argv[0] : "";
  25.     ++argv;
  26.     show_help = *argv ? (strncmp (*argv, "-h", 2) == 0) : 0;
  27.  
  28.     if (show_help) {
  29.     do_show_help ();
  30.     exit (0);
  31.     } /* if (show_help) */
  32.  
  33.     if (*argv == NULL)
  34.     doit (50, stdin);
  35.     else {
  36.     FILE *fp, *fopen ();
  37.  
  38.     if ((fp = fopen (*argv, "r")) == NULL)
  39.         fprintf (stderr, "%s: Couldn't open '%s' for reading\n",
  40.             this_program, *argv);
  41.     else {
  42.         doit (50, fp);
  43.         fclose (fp);
  44.     } /* else*/
  45.     } /* else */
  46.     exit (0);
  47. } /* main */
  48.  
  49.  
  50. doit (len, infp)
  51. int len;
  52. FILE *infp;
  53. {
  54.     int i, j;
  55.     FILE *fp, *fopen ();
  56.  
  57.     write (1, &len, sizeof (int));
  58.     for (i = 0; i < len; i++)
  59.     for (j = 0; j < len; j++) {
  60.         char s[1000];
  61.         float f;
  62.         double atof ();
  63.  
  64.         fscanf (infp, "%*s %*s %s\n", s);
  65.         f = atof (s);
  66.         write (1, &f, sizeof (float));
  67.     }
  68.  
  69. } /* doit */
  70.  
  71.  
  72. do_show_help ()
  73. {
  74.     fprintf (stderr, "%s:  Convert GNUplot to heightfield\n\n", this_program);
  75.     fprintf (stderr, "***WARNING*** The data is expected to be 50x50!!\n\n");
  76.     fprintf (stderr, "SWITCHES [you can use any unique prefix]:\n");
  77.  
  78.  
  79.     fprintf (stderr, "\t-help,?\tShow this HELP message\n");
  80. } /* show_help */
  81.